package cy.jsonview.code;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.support.hsf.HSFJSONUtils;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Title: SortTest
 * @Author Hoda 2022/4/25 9:15 上午
 * @Description:
 */
public class SortTest {

    public static void main(String[] args) {
        List<User> userList = new ArrayList<>();
        userList.add(new User(222L, "张三"));
        userList.add(new User(12L, "李四"));
        userList.add(new User(23L, "王五"));
        userList.add(new User(333L, "赵六"));
        String s = JSON.toJSONString(userList);
        System.out.println("排序前：" + s);

        List<User> sortList = userList.stream().sorted(Comparator.comparing(User::getId)).collect(Collectors.toList());
        String s1 = JSON.toJSONString(sortList);
        System.out.println("排序后：" + s1);
    }


    public static class User {
        private Long id;

        private String name;

        public User(Long id, String name) {
            this.name = name;
            this.id = id;
        }

        public Long getId() {
            return id;
        }

        public void setId(Long id) {
            this.id = id;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }
}
